import SlopeAspect from './SlopeAspect'
export default class Slope{
    _viewer:any
    _slopePrimitives:Array<any>
    _exposurePrimitives:Array<any>
    saObj:any
    constructor(viewer){
        this._viewer=viewer
        this._slopePrimitives=[]
        this._exposurePrimitives=[]
    }
    get slopePrimitives(){
        return this._slopePrimitives
    }
    get exposurePrimitives(){
        return this._exposurePrimitives
    }
    createSlope(errorCallback,option){    
        const {rule,num}=option
        let viewer=this._viewer
        if (!viewer.terrainProvider._layers) {
          if (errorCallback && typeof errorCallback == "function")
            errorCallback("请先开启地形");
          return;
        }
        const callback = (e) => {
          this._slopePrimitives.push(e);
          console.log(e, "cakscs");
        };
        this.saObj = new SlopeAspect(viewer, 'slope', callback);
        if (rule == "distance") this.saObj.createNew4Distance(num);
        if (rule == "num") this.saObj.createNew4Num(num * 100);
    }
    createExposure(errorCallback,option){   
        const {rule,num}=option
        let viewer=this._viewer
        if (!viewer.terrainProvider._layers) {
          if (errorCallback && typeof errorCallback == "function")
            errorCallback("请先开启地形");
          return;
        }
        const callback = (e) => {
          this._exposurePrimitives.push(e);
          console.log(e, "cakscs");
        };
        this.saObj = new SlopeAspect(viewer, 'exposure', callback);
        if (rule == "distance") this.saObj.createNew4Distance(num);
    
        if (rule == "num") this.saObj.createNew4Num(num * 100);
    }
    removeAllExposure(){
        let viewer=this._viewer
        this._exposurePrimitives.forEach((item) => {
            item.forEach((element) => {
              viewer.scene.primitives.remove(element);
            });
          });
          this._exposurePrimitives=[]
    }
    removeAllSlope(){
        let viewer=this._viewer
        this.saObj.clearSlope()
        this._slopePrimitives.forEach((item) => {
            item.forEach((element) => {
              viewer.scene.primitives.remove(element);
            });
          });
        this._slopePrimitives=[]
    }
    }